package demo4;

import java.util.Objects;

public class Duck extends Animal implements IRun,IFly,ISwim{
    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃鸭粮");
    }

    @Override
    public void fly() {
        System.out.println(this.name+"正在飞");
    }

    @Override
    public void run() {
        System.out.println(this.name+"正在跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name+"正在游泳");
    }

    @Override
    public int hashCode() {
        return Objects.hash(name,age);
    }

    public boolean equals(Object obj){
        if(obj==null){
            return false;
        }
        if(this==obj){
            return true;
        }
        if(!(obj instanceof Duck)){
            return false;
        }
        Duck tmp=(Duck) obj;
        return tmp.name.equals(this.name)&& tmp.age==this.age;
    }
}
